extends layout

block content
  div.row(ng-controller="ChatController")
      div.col-sm-4
        div
          h4 在线人列表
            span(class="badge", id="user_count")
          ul(ng-repeat="user in users")
            li
              a(ng-href="#", ng-bind="user.name")

      div.col-sm-8
        div
          h4 聊天内容
        div
          div#content

          div
              form(name="chatForm",role="form", ng-submit="send_msg()")
                  div.row
                      div.form-group.col-sm-4
                          input(type="text", name="nickName", ng-model="nickName", class="form-control", value="小天鹅", required)
                      div.form-group.col-sm-8
                          input(type="text",name="msg", ng-model="msg", class="form-control", required)
                  div.form-group
                      input(type="submit", value="提交", class="btn btn-primary", ng-disabled="chatForm.$invalid")

  script(src="/socket.io/socket.io.js")
  script
      | io = io.connect("http://local.tulingdao.com:9999/");
      | window.sio = io;  //设置为全局变量
      | io.on("server_msg", function(msg) {
      |    $("#content").append("<p>"+msg+"</p>");
      | });
      | io.on("server_new_msg", function(msg) {
      |    console.info(msg);
      | });
      | io.on("user_count", function(count) {
      |    console.info(count);
      |    $("#user_count").html(count);
      | });
  script(src="/js/chat.js")